import App from "../../btoolkit/framework/App";
import BButton from "../../btoolkit/components/BButton";
import SceneManager, { SwapMethod } from "../../btoolkit/framework/SceneManager";
import PanelChildLock from "../../common/PanelChildLock";
import Guide, { GuideType } from "../../btoolkit/guide/Guide";
import AudioManager from "../../btoolkit/AudioManager";
import SDKManager from "../../btoolkit/sdk/SDKManager";
import { BannerPos } from "../../btoolkit/sdk/ADBase";
import QuLe from "../../btoolkit/sdk/QuLe";
import Wait from "../../btoolkit/components/Wait";
import FriendlyLinkBar from "../../common/FriendlyLinkBar";
import BtnShare5Times from "../../common/BtnShare5Times";
import { PreloadConfig } from "../../global/Config";

const { ccclass, property } = cc._decorator;

@ccclass
export default class LaunchCanvas extends cc.Component {

    @property(cc.Label)
    copyright: cc.Label = null;
    @property(cc.Node)
    btnStart: cc.Node = null;

    onLoad() {
        BButton.addButton(this.btnStart).setTouchUpEvent(this.onBtnStartClick, this);
        Guide.startGuide(0, this.btnStart, GuideType.Zoom, true);
        this.copyright.string = '';
    }

    start() {
        this.btnStart.active = false;

        App.instance.init(PreloadConfig, () => {
            this.copyright.string = '软著登记号：' + QuLe.instance.remoteConfig.copyright;
            SDKManager.instance.showBanner(BannerPos.BottomLeft);
            //判断锁屏休息还是正常游戏
            if (!PanelChildLock.checkAndLock()) {
                //播放游戏名字声音
                AudioManager.playBGM('bgm_Start');
                AudioManager.playVoice('voice_GameName');
            }
            this.btnStart.active = true;
        });

        FriendlyLinkBar.instance.setToLeft();
        BtnShare5Times.instance.setToLeft();
    }

    onBtnStartClick() {
        Wait.show();
        SDKManager.instance.login((success: boolean) => {
            QuLe.instance.login((success: boolean) => {
                Wait.hide();
                SceneManager.swapToScene('main', SwapMethod.BlackFade);
            });
        })
    }

}
